package view;

import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import java.awt.Font;

import javax.swing.JLabel;

import control.SudokuLoeser;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Loesungsfenster extends JFrame {

	private JPanel contentPane;
	
	private GrundGUI grundGUI;
	
	public void setGrundGUI(GrundGUI grundGUI) {
		this.grundGUI = grundGUI;
	}
	
	public JPanel getJPane() {
		return contentPane;
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Loesungsfenster frame = new Loesungsfenster();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Loesungsfenster() {
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnJaBitte = new JButton("Ja, bitte!");
		btnJaBitte.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SudokuLoeser loeser = new SudokuLoeser(grundGUI.getSudoku());
				loeser.loeseMitBacktracking();
				grundGUI.setSudoku(loeser.getSudoku());
				for (int i=0; i<9; i++) {
					for (int j=0; j<9; j++) {
						grundGUI.btnFeld[i][j].setText(grundGUI.getSudoku().byteSudokuFeld[i][j] + "");
						grundGUI.btnFeld[i][j].setBackground(Color.white);
					}
				}
				grundGUI.getJFrame().setEnabled(true);
				dispose();
			}
		});
		btnJaBitte.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		btnJaBitte.setBounds(140, 145, 158, 29);
		contentPane.add(btnJaBitte);
		
		JButton btnNeinDanke = new JButton("Nein, danke!");
		btnNeinDanke.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				grundGUI.getJFrame().setEnabled(true);
				grundGUI.getStoppuhr().setBZeitLaeuft(true);
				dispose();
			}
		});
		btnNeinDanke.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		btnNeinDanke.setBounds(140, 198, 158, 29);
		contentPane.add(btnNeinDanke);
		
		JLabel lblWillstDuDas = new JLabel("Willst du das Sudoku wirklich l\u00F6sen lassen?");
		lblWillstDuDas.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		lblWillstDuDas.setBounds(30, 32, 382, 49);
		contentPane.add(lblWillstDuDas);
	}
}
